#include "stdio.h"
#include "stdlib.h"
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <sys/errno.h>
#ifdef __sun
#include <sys/sockio.h>
#endif
#include <unistd.h>
#include <arpa/inet.h>
int main()
{
	struct sockaddr *sa;
	int i;
	int sock;
	sock=socket(AF_INET, SOCK_DGRAM, 0);
	char *buf,*ptr;
	struct ifconf ifc;
	struct ifreq *ifr;
	int len=100*sizeof(struct ifreq);
	int lastlen=0;
	for(;;)
	{
		buf=(char*)malloc(len);
		ifc.ifc_len=len;
		ifc.ifc_buf=buf;
		if(ioctl(sock, SIOCGIFCONF, &ifc)<0)
		{
			if((errno != EINVAL)||(lastlen!=0))
				printf("ioctrl error\n");
		}	
		else
		{	
			if(ifc.ifc_len==lastlen)
				break;
			lastlen=ifc.ifc_len;
		}
		len+=10*sizeof(struct ifreq);
		free(buf);
	}
	ptr=buf;
	for(ptr=buf; ptr<buf+ifc.ifc_len; ptr+=sizeof(struct ifreq))
	{
		ifr=(struct ifreq*)ptr;
		if(ifr->ifr_addr.sa_family!=AF_INET)
			continue;
		struct sockaddr_in *sa=(struct sockaddr_in*)&(ifr->ifr_addr);
		printf("%s:%s\n", ifr->ifr_name, inet_ntoa(sa->sin_addr));
	}
}
